package com.sky.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Employee;
import com.sky.entity.Setmeal;
import com.sky.mapper.DishMapper;
import com.sky.mapper.SetmealMapper;
import com.sky.result.PageResult;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SetmealServiceImpl implements SetmealService {
    @Autowired
    private SetmealMapper setmealMapper;

    @Autowired
    private DishMapper dishMapper;
    /**
     * 新增套餐
     * @param setmealDTO
     */
    @Override
    public void AddSetmeal(SetmealDTO setmealDTO) {
        Setmeal setmeal = new Setmeal();
        //拷贝
        BeanUtils.copyProperties(setmealDTO,setmeal);
        //设置信息
        setmeal.setStatus(1);

        setmealMapper.AddSetmeal(setmeal);
    }


    /**
     * 套餐分页查询
     * @param setmealPageQueryDTO
     * @return
     */
    @Override
    public PageResult PageQuery(SetmealPageQueryDTO setmealPageQueryDTO) {
        PageHelper.startPage(setmealPageQueryDTO.getPage(),setmealPageQueryDTO.getPageSize());
        Page<Setmeal> page = setmealMapper.PageQuery(setmealPageQueryDTO);
        long total = page.getTotal();
        List<Setmeal> records = page.getResult();
        PageResult pageResult = new PageResult();
        pageResult.setTotal(total);
        pageResult.setRecords(records);
        return pageResult;
    }

    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @Override
    public SetmealDTO FindSetmealById(Integer id) {
        SetmealDTO setmealDTO = new SetmealDTO();
        Setmeal setmeal=setmealMapper.FindSetmealById(id);
        BeanUtils.copyProperties(setmeal,setmealDTO);
        return setmealDTO;
    }

    @Override
    public void UpdateStutas(Integer status, Long id) {
        Setmeal setmeal = new Setmeal();
        setmeal.setStatus(status);
        setmeal.setId(id);
        setmealMapper.UpdateStutas(setmeal);
    }

    @Override
    public void UpDateSetmeal(SetmealDTO setmealDTO) {
        Setmeal setmeal = new Setmeal();
        BeanUtils.copyProperties(setmealDTO,setmeal);
        setmealMapper.UpDateSetmeal(setmeal);
    }

    @Override
    public void DeleteSetmealList(Long id) {
        setmealMapper.DeleteSetmealList(id);
    }

    @Override
    public List<Setmeal> GetUserSetmealList(Long categoryId) {
        return setmealMapper.GetUserSetmealList(categoryId);
    }

    @Override
    public List<DishItemVO> GetDishBySetmealId(Integer id) {
        return setmealMapper.GetDishBySetmealId(id);
    }
}
